/**
 * 
 */
package TestCases;

import java.io.FileNotFoundException;

import Tracer.*;
import XMLScene.RTSurface;
import XMLScene.RTTriangle;
import junit.framework.TestCase;

/**
 * @author forrestzhao
 * 
 */
public class RTTriangleTest extends TestCase {
	private RTTriangle triangle = null;

	/**
	 * @param name
	 */
	public RTTriangleTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();
		RTVector c0 = new RTVector(0.0f, 0.0f, 0.0f);
		RTVector v1 = new RTVector(0.0f, 1.0f, 1.0f);
		RTVector v2 = new RTVector(0.0f, 2.0f, 1.0f);
		triangle = new RTTriangle(c0, v1, v2);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		triangle = null;
	}

	/**
	 * Test method for setSurface Test it works well after performing Test it
	 * works well after performing
	 */
	public final void testSetSurface() throws FileNotFoundException {
		RTSurface surface = new RTSurface("earthmap.ppm");
		triangle.setSurface(surface);
		assertNotNull(triangle.getSurface());
		assertEquals("Surface image path error", 640, triangle.getSurface()
				.getPigment().getBitmap().width());
	}

	/**
	 * Test method for getSurface() Test it works well after performing
	 * getSurface
	 */
	public final void testGetSurface() {
		RTSurface surface = triangle.getSurface();
		assertNotNull(surface);
		assertNotNull(surface.getPigment().getColor());
		assertTrue("Surface color error", surface.getPigment().getColor()
				.isEqual(new RTColor(0.0f, 0.0f, 0.0f)));
	}

	/**
	 * Test method for RTTriangle Test it works well after performing RTTriangle
	 */
	public final void testGetC0() {
		assertTrue(triangle.getC0().isEqual(new RTVector(0.0f, 0.0f, 0.0f)));
	}

	/**
	 * Test method for getV1() Test it works well after performing getV1
	 */
	public final void testGetV1() {
		assertTrue(triangle.getV1().isEqual(new RTVector(0.0f, 1.0f, 1.0f)));
	}

	/**
	 * Test method for getV2() Test it works well after performing getV2
	 */
	public final void testGetV2() {
		assertTrue(triangle.getV2().isEqual(new RTVector(0.0f, 2.0f, 1.0f)));
	}
}
